/*
 *    led.c  -  led api & driver
 *
 *	  Board:		akae2440
 *    environment:	bootloader & ADS
 *    Author:		akaedu
 *    Date:			2009-5-26
 *    web:			www.akaedu.org
 *
 *
 *	  GPIO address_MAP
 *	  
 *	  CPLD_MAP_BASE	physical address is	0x20800000		
 *	  CPLD_LED		physical address is	0x20800000		
 *	  CPLD_SEG		physical address is	0x20800080
 *	  CPLD_DIP		physical address is	0x208000a0
 *
 *	  GPIO port_MAP
 *
 *	  GPA_PORT~GPB_PORT(130 multi-functional input port pins)
 *	  GPIO_BASE	:	GPACON	:	0x56000000	
 *
 *	  NAME			GPIO		CPLD_IN		CPLD_OUT	GPIO_CON		MODE_bit_CON	GPIO_DAT		MODE_bit_DAT		
 *	  BEEP			GPB0		TOUT0(GPB0)	BEEP		0x56000010		[1:0]			0x56000014		[0]
 *
 *	  GPIO key_scn_MAP
 *
 *	  NAME			PORT_OUT			PORT_IN			
 *	  KEY(sw1)		KBOUT1 : GPB8		KBIN1 : ENT0 : GPF0				
 *	  KEY(sw2)		KBOUT0 : GPB9		KBIN1 : ENT0 : GPF0			
 *	  KEY(sw3)		KBOUT1 : GPB8		KBIN0 : ENT2 : GPF2				
 *	  KEY(sw4)		KBOUT1 : GPB8		KBIN1 : ENT2 : GPF2				
 *
 *	  GPIO_CON						GPIO_DAT				GPIO		MODE_bit_CON		MODE_bit_DAT
 *	  GPBCON : 0x56000010			GPBDAT : 0x56000014		GPB8		[17:16]				[8]			
 *	  GPBCON : 0x56000010			GPBDAT : 0x56000014		GPB9		[19:18]				[9]			
 *	  GPFCON : 0x56000050			GPBDAT : 0x56000054		GPF0		[1:0]				[0]			
 *	  GPFCON : 0x56000050			GPBDAT : 0x56000054		GPF2		[5:4]				[2]			
 *
 */
#include "led.h"

#define CPLD_LED		*((volatile unsigned char *)0x20800000)

int led_init(void)
{
	CPLD_LED = 0x0;
	return 0;
}

int led_on(int num)
{
	CPLD_LED |= 1<<num;
	
	return 0;
}

int led_off(int num)
{
	CPLD_LED &= ~(1<<num);
	
	return 0;
}
static void delay(int time)
{
	int i,j;
	
	for (i = 0; i < time; i++)
		for (j = 0; j < 1000000; j++)
		;
}

int led_on_all(void)
{
	CPLD_LED |= 0xff;
	
	return 0;
}

int led_off_all(void)
{
	CPLD_LED &= 0x0;
	
	return 0;
}

int led_test(int argc,char *argv[])
{
	int i;
	
	led_init();
	
	for (i = 0; i < 8; i++)
	{
		led_on(i);
		delay(1);
	}
	while(1)
	{
	led_off_all();
	delay(1);
	led_on_all();
	delay(1);
	}
	return 0;
}


